<!DOCTYPE HTML>
<#--
/**
 * Copyright 2012 Claude Houle claude.houle@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-->
<#compress>
<html>
<#escape x as x?html>
	<#include "/web/widgets/ui-button.ftl" />
	<#include "/web/widgets/ui-dialog.ftl" />
	<#include "/web/widgets/ui-dialog-acknowledge.ftl" />
	<#include "/web/widgets/ui-textfield.ftl" />
	<#include "/web/widgets/ui-select.ftl" />
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta http-equiv="pragma" content="no-cache" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="expires" content="0" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

		<link rel="shortcut icon" href="/favicon.ico" />
		<link rel="stylesheet/less" type="text/css" href="/login" />
		<link rel="stylesheet" type="text/css" href="/libs/jqueryui/jquery-ui-1.8.16.custom.css" />

		<script type="text/javascript" src="/libs/less-1.2.0.min.js"></script>
		<script type="text/javascript" src="/libs/jquery/jquery-1.7.1.min.js"></script>
		<script type="text/javascript" src="/libs/jqueryui/jquery-ui-1.8.16.custom.min.js"></script>

		<script type="text/javascript">
			$().ready( function(){
				$("#btn_login").click( 	function( event ) {
					event.stopImmediatePropagation();

					$.ajax("${urlAuth}", {
						type: 'POST',
						async: true,
						cache: false,
						data:   {
							username: $('#f_user').val(),
							password: $('#f_pwd').val(),
							language: $('#f_lang .uic-select-choice-selected').attr('data-value')
						},
						error:  function( jqXHR, status, error ){
							if( error == 'Unauthorized' ){
								<@dialog_acknowledge id="dlg_auth" captionConfirm="OK" message="" />
								$("#dlg_auth").text(jqXHR.responseText);
							}
						},
						success:  function( data, status, jqXHR ){
							<#if refreshOnSuccess>
								window.location.reload();
							<#else>
								if( data != "")
									window.location.replace( data );
								else
									window.location.replace('${redirectUrl}');
							</#if>
						},
						timeout: 60000
					});
				} );

				$("#f_lang").bind('list-selection-update', function( event ){
					if( event.value != "" && $("#f_user").val() == "" && $("#f_pwd").val() == "" ){
						$.ajax("${urlI18n}", {
							type: 'POST',
							async: true,
							cache: false,
							data:   {
								language: event.value
							},
							error:  function( jqXHR, status, error ){
								window.alert('An error occured while resetting password. Please try again');
							},
							success:  function( data, status, error ){
								window.location.reload(false);
							},
							timeout: 60000
						});
					}
				} );

				$("#lnkForgotPwd").click(function(){
					window.location.replace('${urlForgotPwd}');
				});

				$(window).keypress( function(event){
			 		if ( event.which == 13 ) {
						event.preventDefault();
				   		$("#btn_login").click();
					}
				});
			});
		</script>

		<title>${i18n('headtitle')}</title>
	</head>
	<body>
		<div class="uic-login">
			<div class="uic-login-title"></div>
				<center>
					<div class="uic-login-container uic-box-shadow ">
						<div class="uic-login-header ">
							<div class="uic-login-header-row">
								<div class="uic-login-header-row-left">
									<div class="uic-login-env">
										${env}
									</div>
								</div>
								<div class="uic-login-header-row-right">

								</div>
							</div>
							<div class="uic-login-header-row uic-login-header-row-links">
								<a id="lnkForgotPwd" class="uic-login-link">${i18n("lnkForgotPwd")}</a>
							</div>
						</div>
						<div class="uic-login-content">
							<center>
								<table class="uic-login-form">
									<tr class="uic-login-form-row">
										<td class="uic-login-lbl"><div>${i18n("lblUsername")}</div></td>
										<td class="uic-login-field">
											<@textfield id="f_user" maxlength=20 />
										</td>
									</tr>
									<tr class="uic-login-form-row">
										<td class="uic-login-lbl"><div>${i18n("lblPassword")}</div></td>
										<td class="uic-login-field">
											<@textfield id="f_pwd" password=true maxlength=255 />
										</td>
									</tr>
									<tr class="uic-login-form-row">
										<td class="uic-login-lbl"><div>${i18n("lblLanguage")}</div></td>
										<td class="uic-login-field">
											<@select id="f_lang" choices=langChoices emptyValue="" />
										</td>
									</tr>
								</table>
							</center>
						</div>
						<div class="uic-login-action">
							<center>
								<@button id="btn_login" caption=i18n("btnLogin") />
							</center>
						</div>
					</div>
				</center>
			</div>
		</div>

	</body>
</#escape>
</html>
</#compress>